from common.unit import AndroidUI
from common.home_page import HomePageObject


class Login:
    def __init__(self):
        self.unit = AndroidUI
        self.home = HomePageObject()
        self.cleaner = "9999010001A1001"  # 赵清理人二维码
        self.waike = "9999010001B1001"  # 外科
        self.qianhushi = "9999010001A2001"  # 钱护士
        self.zancunjian = "9999010001B2001"  # 暂存间
        self.sunchuzhi = "9999010001A3001"  # 孙处置
        self.driver = AndroidUI.get_webdriver()

    def back_button(self):
        self.driver.keyevent(4)

    # 清理人登录
    def cleaner_login(self):
        self.unit.scan(self.cleaner)
        try:
            self.home.home_page()
            # self.driver.find_element_by_text("点击拉取机型配置信息")
            print("测试清理人登录成功")
            AndroidUI().write_result("扫描清理人登录测试", "成功")
            self.back_button()
        except:
            print("测试清理人登录失败")
            AndroidUI.capture()
            AndroidUI().write_result("测试清理人登录", "失败")

    # 使用科室进行登录操作
    def keshi_login(self):
        self.unit.scan(self.waike)
        try:
            self.home.home_page()
            # self.driver.find_element_by_text("点击拉取机型配置信息")
            print("扫描科室二维码进行登录，登录成功，返回结果错误")
            AndroidUI.capture()
            AndroidUI().write_result("扫描科室二维码进行登录，登录成功", "错误")
            self.back_button()
        except:
            print("扫描科室二维码进行登录，登录失败，返回结果正确")
            AndroidUI().write_result("扫描科室二维码进行登录，登录失败", "正确")

    # 使用护士角色进行登录操作
    def hushi_login(self):
        self.unit.scan(self.qianhushi)
        try:
            self.home.home_page()
            # self.driver.find_element_by_text("点击拉取机型配置信息")
            print("扫描护士二维码进行登录，登录成功，返回结果错误")
            AndroidUI.capture()
            AndroidUI().write_result("扫描护士二维码进行登录，登录成功", "错误")
            self.back_button()
        except:
            print("扫描护士二维码进行登录，登录失败，返回结果正确")
            AndroidUI().write_result("扫描护士二维码进行登录，登录失败", "正确")

    # 扫描暂存二维码进行登录操作
    def zancunjian_login(self):
        self.unit.scan(self.zancunjian)
        try:
            self.home.home_page()
            # self.driver.find_element_by_text("点击拉取机型配置信息")
            print("扫描暂存间进行登录，登录成功，返回结果错误")
            AndroidUI.capture()
            AndroidUI().write_result("扫描暂存间进行登录，登录成功", "错误")
            self.back_button()
        except:
            print("扫描暂存间进行登录，登录失败，返回结果正确")
            AndroidUI().write_result("扫描暂存间进行登录，登录失败", "正确")

    # 扫描暂存二维码进行登录操作
    def chuzhi_login(self):
        self.unit.scan(self.sunchuzhi)
        try:
            self.home.home_page()
            # self.driver.find_element_by_text("点击拉取机型配置信息")
            print("扫描处置人员进行登录，登录成功，返回结果错误")
            AndroidUI.capture()
            AndroidUI().write_result("扫描处置人员进行登录，登录成功", "错误")
            self.back_button()
        except:
            print("扫描处置人员进行登录，登录失败，返回结果正确")
            AndroidUI().write_result("扫描处置人员进行登录，登录失败", "正确")

    def start_test(self):

        # self.keshi_login()
        # self.hushi_login()
        # self.zancunjian_login()
        # self.chuzhi_login()
        self.cleaner_login()


if __name__ == '__main__':
    l = Login()
    # l.cleaner_login()
    # l.back_button()

    # l.keshi_login()

    l.start_test()
